﻿using Core.Utility.Helper;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Core.Utility.Config
{
    /// <summary>
    /// Json配置模型
    /// </summary>
    public class JsonConfig
    {
        /// <summary>
        /// 创建人
        /// </summary>
        [JsonProperty("created_by", Order = 1)]
        public virtual long? CreatedBy
        {
            get;
            set;
        }

        /// <summary>
        /// 创建人名称;创建人名称冗余存储
        /// </summary>
        [JsonProperty("create_by_name", Order = 2)]
        public virtual string? CreateByName
        {
            get;
            set;
        }

        /// <summary>
        /// 创建时间
        /// </summary>
        [JsonProperty("created_time", Order = 3)]
        public virtual DateTime? CreatedTime
        {
            get;
            set;
        }

        /// <summary>
        /// 更新人
        /// </summary>
        [JsonProperty("updated_by", Order = 4)]
        public virtual long? UpdatedBy
        {
            get;
            set;
        }

        /// <summary>
        /// 更新人名称;修改人名称冗余存储
        /// </summary>
        [JsonProperty("updated_by_name", Order = 5)]
        public virtual string? UpdatedByName
        {
            get;
            set;
        }

        /// <summary>
        /// 更新时间
        /// </summary>
        [JsonProperty("updated_time", Order = 6)]
        public virtual DateTime? UpdatedTime
        {
            get;
            set;
        }

        /// <summary>
        /// 数据
        /// </summary>
        [JsonProperty("data", Order = 7)]
        public virtual List<JsonConfigSection>? Data { get; set; }

        /// <summary>
        /// 乐观锁;用于数据并发操作时使用,数据每次更新后，改变此值
        /// </summary>
        [JsonProperty("revision", Order = 8)]
        public virtual string? Revision
        {
            get;
            set;
        }

    }

    /// <summary>
    /// Json配置节点
    /// </summary>
    public class JsonConfigSection
    {
        /// <summary>
        /// 节点名，存储、读取时不区分大小写，一律以小写进行操作
        /// </summary>
        [JsonProperty("section", Order = 1)]
        public string? Section { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        [JsonProperty("item", Order = 2)]
        public virtual List<JsonConfigSectionItem>? Item { get; set; }
    }

    /// <summary>
    /// Json配置节点内容
    /// </summary>
    public class JsonConfigSectionItem
    {
        /// <summary>
        /// 键，存储、读取时不区分大小写，一律以小写进行操作
        /// </summary>
        [JsonProperty("key", Order = 1)]
        public string? Key { get; set; }

        /// <summary>
        /// 值，存储时，将原内容进行 <see cref="Convert.ToBase64String(byte[])"/> 存储
        /// <para>存储转换使用方法 <see cref="ValueTypeConvertHelper.ToUtf8Base64String(string, string)"/> 进行转换</para>
        /// <para>读取转换使用方法 <see cref="ValueTypeConvertHelper.Base64StringToUtf8String(string, string)"/> 进行转换</para>
        /// </summary>
        [JsonProperty("content", Order = 2)]
        public string? Content { get; set; }
    }
}
